package com.zhangtai.modules.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhangtai.modules.dto.InsuranceDto;
import com.zhangtai.modules.dto.SecurityChangeDto;
import com.zhangtai.modules.entity.insurance.InsuranceEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-11-23 14:28:02
 */
@Mapper
public interface InsuranceDao extends BaseMapper<InsuranceEntity> {

    @Select("<script>SELECT " +
            "t1.*, " +
            "(SELECT count(1) FROM tb_employee_insurance WHERE insurance_id = t1.id AND is_delete = 0 AND status = 1) AS realNumber " +
            " FROM " +
            " tb_insurance t1 " +
            "<where> " +
            "<if test='companyId!=null and companyId!=&apos;&apos;'>and t1.company_id = '${companyId}' </if>" +
            "<if test='insuranceUnit!=null and insuranceUnit!=&apos;&apos;'>and t1.insurance_unit like '%${insuranceUnit}%' </if>" +
            "<if test='status!=null'>and t1.status  = '${status}' </if>" +
            "</where>" +
            "</script>")
    List<InsuranceDto> getInsuranceList(@Param("companyId") Long companyId,
                                        @Param("insuranceUnit") String insuranceUnit,
                                        @Param("status") Integer status,
                                        @Param("startTime") String startTime,
                                        @Param("endTime") String endTime,
                                        Page<InsuranceDto> page);
}
